package ModelLayer;

import java.util.ArrayList;
/**
 * Write a description of class DVDContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DVDContainer
{
    public ArrayList<DVD> DVDContainer;
    private static DVDContainer instance;

    public DVDContainer()
    {
        DVDContainer = new ArrayList<DVD>();
    }
    
    public static DVDContainer getSingleton()
    {
        if(instance == null)
        {
            instance = new DVDContainer();
        }
        return instance;
    }
    
    public void createDVD(DVD dvd)
    {
        DVDContainer.add(dvd);
    }
    
    public DVD findDVD(int no)
    {
        int index = 0;
        boolean found = false;
        while(index < DVDContainer.size() && !found)
        {
            if(DVDContainer.get(index).getId() == no)
            {
                found = true;
            }
            else
            {
                index++;
            }
        }
        return DVDContainer.get(index);
    }
    
    public void deleteDVD(int id)
    {
        int index = 0;
        boolean found = false;
        while(index < DVDContainer.size() && !found)
        {
            if(DVDContainer.get(index).getId() == id)
            {
                found = true;
                DVDContainer.remove(index);
            }
            else
            {
                index++;
            }
        }
    }
    

    
    public Specimen getSpecimen(int dvdId, int specimenId)
    {
        Specimen specimen = null;
        int index = 0;
        boolean found = false;        
        while(index < DVDContainer.size() && !found)
        {
            if(DVDContainer.get(index).getId() == dvdId)
            {
                found = true;
                specimen = DVDContainer.get(index).getSpecimen(specimenId);
            }
            else
            {
                index++;
            }
        }
        return specimen;
    }
}